package com.atguigu09.inner;

/**
 * ClassName: OuterClassTest
 * Package: com.atguigu09.inner
 * Description:
 *
 * @Author ZY
 * @Create 21:47
 * @Version 1.0
 */
public class OuterClassTest {

    public static void main(String[] args) {

        //1.创建Person的静态的成员内部类的实例
        Person.Dog dog = new Person.Dog(); //外部类名.内部类名 对象 = new 外部类名.内部类名()
        dog.eat();


        //2.创建Person的非静态的成员内部类的实例
        Person person = new Person();         // 先创建外部类实例
        Person.Bird bird = person.new Bird(); // 再通过外部类实例创建内部类对象 --- 外部类实例.new 内部类名()
        bird.eat();
        bird.show("黄鹂");
        bird.show1();

    }

}

class Person{//外部类

    String name = "tom";
    int age = 1;

    //静态的成员内部类
    static class Dog{
        public void eat(){
            System.out.println("狗吃骨头");
        }
    }

    //非静态的成员内部类
    class Bird{
        String name = "啄木鸟";
        public void eat(){
            System.out.println("鸟吃虫子");
        }

        public void show(String name){
            System.out.println("age = " + age);
            System.out.println("name = " + name);//形参
            System.out.println("name = " + this.name);//内部类的属性
            System.out.println("name = " + Person.this.name);//外部类的属性
        }

        public void show1(){
            eat();
            this.eat();
            Person.this.eat();
        }
    }

    public void eat(){
        System.out.println("人吃饭");
    }


    //成员方法
    public void method(){

        //局部内部类
        class InnerClass1{

        }
    }

    //成员构造器
    public Person(){

        //局部内部类
        class InnerClass2{

        }

    }

    //成员代码块
    {
        //局部内部类
        class InnerClass3{

        }

    }
}




